<?php
namespace app\admin\controller;
use app\Base;
use think\facade\Db;
class Site extends Base{
	//private $request;
	//控制台首页信息
    public function index()
    {
		$ordernum=Db::name('order')->where("paystatus",">",0)->count();
		$usernum=Db::name('member')->count();
		$account=Db::name('member')->sum('account');
		$paynum=Db::name('paylist')->where("status",">",0)->count();//支付笔数
		
		$t=time()-3600*24*10;
		$label=[];
		$vals=[];
		$cursor=Db::name('login_log')->field("FROM_UNIXTIME(inputtime,'%Y-%m-%d') as rq,count(*) as loginum")->where("inputtime",">",$t)->where("type",1)->group("rq")->order("rq as")->cursor();
		foreach($cursor as $key=>$val)
		{
			$label[]=$val['rq'];
			$vals[]=$val['loginum'];
		}
		
		$data=array(
			'tj'=>array('ordernum'=>$ordernum,'usernum'=>$usernum,'account'=>$account,'paynum'=>$paynum),
			'label'=>$label,
			'data'=>$vals
		);
		
		$this->setobj($data);
		
		return $this->ok();
    }
	
	public function setting()
	{
		$sys=Db::name('site')->where('siteid',1)->find();
		if($this->request->post('siteid'))
		{			
			Db::name('site')->save($this->request->post());
			return $this->ok();
		}
		else{
			$this->setobj($sys);
			return $this->ok();
		}
	}
	
	public function resetpw()
	{
		$userid=$this->request->admin['userid'];
		if(!$this->request->post('password'))
		{
			return $this->kerror('参数不正确');
		}
		
		$password=skey($this->request->post('password'));
		Db::name('admin')->where('userid',$userid)->update(array('password'=>$password));
		return $this->ok();
		
	}
		
	
	 
	
}
